package com.imooc.mall.controller;

import com.github.pagehelper.PageInfo;
import com.imooc.mall.common.ApiRestResponse;
import com.imooc.mall.model.pojo.Product;
import com.imooc.mall.model.request.ProductListReq;
import com.imooc.mall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class ProductController {

    @Autowired
    ProductService productService;

    @PostMapping("/product/detail")
    public ApiRestResponse detaiil(@RequestParam("id") Integer id) {
        final Product detail = productService.detail(id);
        return ApiRestResponse.success(detail);
    }

    @PostMapping("/product/list")
    public ApiRestResponse list(
            @Valid
            @RequestBody ProductListReq productListReq
    ) {
        PageInfo list = productService.list(productListReq);
        return ApiRestResponse.success(list);
    }
}
